﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TextEditorDP
{
    public class CList<Item>: IAbstractList<Item>
    {
        List<Item> items = new List<Item>();

        public int Count
        {
            get { return items.Count; }
        }

        public void Add(int index, Item r) {
            if (!Assert<Item>.checkNull(r))
                if (Assert<Item>.checkTrue(index >= 0 && index <= items.Count))
                    items.Insert(index, r);
        }

        public Item Get(int index)
        {
            if (Assert<Item>.checkRange(index, items))
                return items.ElementAt(index);
            return default(Item);
        }

        internal int IndexOf(Item item)
        {
            return items.IndexOf(item);
        }

        internal void Remove(Item item)
        {
            if (!Assert<Item>.checkNull(item))
            {
                items.Remove(item);
            }
        }

        #region IAbstractList<Item> Members

        public Iterator<Item> CreateIterator()
        {
            return new Iterator<Item>(this);
        }

        #endregion
    }
}
